package com.yc.fav.web;

import com.yc.fav.FavConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/8/4
 * Email haijunzhou@hnit.edu.cn
 */
@WebListener
public class MyServletContextListener implements ServletContextListener {

    AnnotationConfigApplicationContext cxt;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("-----------contextInitialized---------------");
        cxt = new AnnotationConfigApplicationContext(FavConfig.class);
        sce.getServletContext().setAttribute("cxt",cxt);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("-----------contextDestroyed---------------");
        cxt.close();
    }
}
